[SPARK-57004][SQL] Simplify CheckOverflowInSum codegen under ANSI mode#56063
Draft
gengliangwang wants to merge 1 commit into
Draft
[SPARK-57004][SQL] Simplify CheckOverflowInSum codegen under ANSI mode#56063gengliangwang wants to merge 1 commit into
gengliangwang wants to merge 1 commit into
Conversation
### What changes were proposed in this pull request? Introduce `DecimalExpressionUtils.java` with a `checkOverflowInSum(Decimal, int, int, boolean, QueryContext)` static helper and call it from `CheckOverflowInSum.doGenCode` and the eval path. Codegen body shrinks from a 10-line if/else block (init `ev.value` to null, branch on `childGen.isNull`, conditionally throw, conditionally call `toPrecision` + re-set `ev.isNull`) to 4 lines (single helper call + post-check). Eval is now a single delegating call. ### Why are the changes needed? Part of SPARK-56908 (umbrella). `CheckOverflowInSum` is emitted around every decimal `Sum` and is one of the longer remaining inline ANSI bodies. Collapsing the per-call-site body shrinks generated Java source and Janino compile time on aggregation-heavy plans. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? ``` build/sbt "catalyst/testOnly *DecimalExpressionSuite *AggregateExpressionSuite" build/sbt "sql/testOnly *DataFrameAggregateSuite -- -z sum" ``` 20/20 pass (incl. the SPARK-39208 `CheckOverflowInSum` runtime-context test). ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Cursor 1.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Introduce
DecimalExpressionUtils.javawith acheckOverflowInSum(Decimal, int, int, boolean, QueryContext)static helper and call it fromCheckOverflowInSum.doGenCodeand the eval path.Codegen body shrinks from a 10-line if/else block (init
ev.valueto null, branch onchildGen.isNull, conditionally throw, conditionally calltoPrecision+ re-setev.isNull) to 4 lines (single helper call + post-check). Eval is now a single delegating call.Why are the changes needed?
Part of SPARK-56908 (umbrella).
CheckOverflowInSumis emitted around every decimalSumand is one of the longer remaining inline ANSI bodies. Collapsing the per-call-site body shrinks generated Java source and Janino compile time on aggregation-heavy plans.Does this PR introduce any user-facing change?
No.
How was this patch tested?
20/20 pass (incl. the SPARK-39208
CheckOverflowInSumruntime-context test).Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor 1.x